﻿

CREATE PROCEDURE [dbo].[sankit_StergeUnitate] 
 @CodUnitate smallint AS
BEGIN
DECLARE @NrDoc AS int
SET @NrDoc = 0

BEGIN TRAN

PRINT '[ChitantaDetaliu]'    
DELETE FROM [ChitantaDetaliu] WHERE IdChitanta In (SELECT IDChitanta FROM Chitanta WHERE [CodUnitate]=@CodUnitate)
IF @@ERROR <>0
    GOTO Eroare 

PRINT '[Chitanta]'    
DELETE FROM [Chitanta] WHERE [CodUnitate]=@CodUnitate
IF @@ERROR <>0
    GOTO Eroare 

PRINT '[SanKitSetup]'    
DELETE FROM [SanKitSetup] WHERE [CodUnitate]=@CodUnitate
IF @@ERROR <>0
    GOTO Eroare 



COMMIT TRAN    
GOTO Gata
Eroare:
  ROLLBACK
  RAISERROR ('Eroare la executia procedurii StergeUnitate',-1,0)
Exista_Documente:
  ROLLBACK
  RAISERROR ('Unitatea nu poate fi stearsa deoarece contine documente!',-1,0)
Exista_Rulaje_Documente:
  ROLLBACK
  RAISERROR ('Unitatea nu poate fi stearsa deoarece contine rulaje - documente!',-1,0)

Gata:

END